package com.sharelogindemo;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class ToastUtil {

	private static Toast toast = null;

	public static void showToast(Context mContext, int resId) {
		try {
			if(mContext != null) {
				View mToastView = LayoutInflater.from(mContext).inflate(R.layout.dialog_toast, null);
				TextView tipTextView = (TextView) mToastView.findViewById(R.id.tip);
				tipTextView.setText(mContext.getResources().getString(resId));
				Toast toast = showToast(mContext, mContext.getResources().getString(resId), Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0 , 0);
				toast.setView(mToastView);
				toast.show();
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void showToast(Context mContext, String content) {
		try {
			if(mContext != null) {
				View mToastView = LayoutInflater.from(mContext).inflate(R.layout.dialog_toast, null);
				TextView tipTextView = (TextView) mToastView.findViewById(R.id.tip);
				tipTextView.setText(content);
				Toast toast = showToast(mContext, content, Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0 , 0);
				toast.setView(mToastView);
				toast.show();
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Toast showToast(Context mContext, String content, int time) {
		try {
			if(mContext != null && !Utils.isNullOrEmpty(content)) {
				if (toast != null) {
					toast.setText(content);
				}else {
					toast = Toast.makeText(mContext, content, time);
				}
				toast.show();
			}
		}catch (Exception e) {
			e.printStackTrace();
		}

		return toast;
	}
}